package org.ooda.distributedsys.loginmodule.functions;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @program: distributedSys
 * @description: Sha tools for string input
 * @author: Aprilies
 * @create: 2023-06-03 12:16
 **/

public class ShaUtils {
    public static String sha(String input) throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] digestByte = digest.digest(input.getBytes());
        StringBuilder stringBuilder = new StringBuilder();
        for (byte b : digestByte) {
            stringBuilder.append(String.format("%02x", b));
        }
        return stringBuilder.toString();
    }
}
